#ifndef _RSSSOCKET_H_
#define _RSSSOCKET_H_

#include "NetWork.h"
#include <list>
#include "../util/std_ex.h"
#include <winsock2.h>
#define BUFFER_SIZE 1024

class RssTcpSocket : NetWork{
public:
	struct Packet{ char data[BUFFER_SIZE]; uint len; };
	RssTcpSocket();
	int ErrorCode() const { return m_errorCode; }
	virtual bool Initial();
	virtual bool Connect(string &addr, UINT remotePort);
	virtual int Send(const char* buf, int len);
	virtual int Read();
	virtual void Close();
	virtual ~RssTcpSocket();
	virtual string GetData();
	virtual void OnStart(){}
	virtual void OnDnsQuery(){}
	virtual void OnConnecting(){}
	virtual void OnWriting(){}
	virtual void OnReading(){}
	virtual void OnEnd(){}
protected:
	enum socketState {NONE=0, DISCONNECTING, CREATED, CONNECTED, ACCEPTING};
	bool m_bWSAStarted;
	int m_errorCode;
	SOCKET s;
	socketState m_socketState;
	list<Packet> m_revData;
	SOCKADDR_IN m_remoteAddress;
	int m_revDataLength;
};
#endif